import 'package:flutter/material.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/page/login/email_login/email_login.dart';
import 'package:full_display/page/login/find_account/find_account_provider.dart';
import 'package:full_display/page/login/phone_login/phone_login.dart';
import 'package:full_display/unit/screen/screen_utility.dart';
import 'package:full_display/unit/toast/toast_util.dart';
import 'package:full_display/unit/widgets/single_select_widget/single_select_widget.dart';
import 'package:provider/provider.dart';

class FindAccountWidget extends StatelessWidget {

  final int initIndex;

  const FindAccountWidget({Key? key, required this.initIndex, }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (_) => FindAccountProvider(),
        )
      ],
      child: FindAccountPage(
        initIndex: initIndex,
      ),
    );
  }
}

class FindAccountPage extends StatefulWidget {

  final int initIndex;

  const FindAccountPage({super.key,required this.initIndex});

  @override
  State<FindAccountPage> createState() => _FindAccountPageState();
}

class _FindAccountPageState extends State<FindAccountPage>
    with SingleTickerProviderStateMixin {
  var _findProvider = FindAccountProvider();

  late PageController _pageController;

  @override
  void initState() {
    _pageController = PageController(initialPage: widget.initIndex);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    _findProvider = context.watch<FindAccountProvider>();
    return Scaffold(
      backgroundColor: ColorPlate.background,
      resizeToAvoidBottomInset: false,
      body: Container(
          margin: EdgeInsets.only(left: 30.0.W, right: 30.0.W, top: 124.0.H),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              SingleSelectWidget(
                selectIndex: widget.initIndex,
                titleList: FindAccountProvider.titleList,
                callBack: (index) {
                  setState(() {
                    _pageController.jumpToPage(index);
                  });
                },
              ),
              Container(
                  margin: EdgeInsets.only(top: 31.0.H),
                  height: 134.0.H,
                  child: PageView(
                    controller: _pageController,
                    children: [
                      PhoneLogin(
                        forgetPassword: () {
                          showToast('获取验证码0');
                        },
                        loginCallBack: (){},
                        type: 1,
                      ),
                      EmailLogin(
                        emailCallBack: () {
                          showToast('获取验证码1');
                        },
                        emailLoginCallBack: (){},
                        type: 1,
                      ),
                    ],
                  )),
              GestureDetector(
                onTap: () {
                  showToast("完成");
                },
                child: Container(
                  alignment: Alignment.center,
                  height: 54.0.H,
                  margin: EdgeInsets.only(top: 39.0.H),
                  width: MediaQuery.of(context).size.width,
                  decoration: BoxDecoration(
                      gradient: const LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: [
                            ColorPlate.tabbar_select,
                            ColorPlate.tabbar_gradient
                          ]),
                      borderRadius: BorderRadius.circular(27)),
                  child: Text(
                    '完成',
                    style: TextStyle(
                      color: ColorPlate.white,
                      fontSize: 17.0.SP,
                    ),
                  ),
                ),
              )
            ],
          )),
    );
  }
}
